//
//  MainViewController.swift
//  SinaWeibo
//
//  Created by mac on 16/1/30.
//  Copyright © 2016年 mac. All rights reserved.
//
import UIKit

class MainViewController: UITabBarController {

    @objc private func plusBtnDidClick() {
//        print(__FUNCTION__)
    }
    
    
    //相当于控制器的入口
    override func viewDidLoad() {
        super.viewDidLoad()
        //打印对象的类型
//        print(tabBar.classForCoder)
        
        let mainTabbar = MainTabBar()

        setValue(mainTabbar, forKey: "tabBar")
        let actionName = "plusBtnDidClick"

        mainTabbar.plusBtn.addTarget(self, action: Selector(actionName), forControlEvents: .TouchUpInside)
//        print(tabBar.classForCoder)
        //添加子视图控制器
        addChildViewControllers()
    }
    
    //私有函数 只有在本类中才可以访问
    private func addChildViewControllers() {
        addChildViewController(HomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(MineTableViewController(), title: "我", imageName: "tabbar_profile")
        
    }
    
    //MARK: 添加单个视图控制器
    private func addChildViewController(vc: UIViewController, title: String,imageName: String) {
        //设置渲染颜色
        tabBar.tintColor = UIColor.orangeColor()
        let nav = UINavigationController(rootViewController: vc)
        vc.title = title

        
        //设置tabbaritem的图片
        vc.tabBarItem.image = UIImage(named: imageName)
        addChildViewController(nav)
    }
    
    
    
}
